package pl.edu.amu.wmi.kino.visualjavafx.model.animation.animationTime;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.Iterator;
// #[regen=yes,id=DCE.DAC73153-B21A-E23C-FDBD-4228BE7F6162]
// </editor-fold> 
public class Timeline implements java.io.Serializable{

    // Code block for changeListeners support start
    protected PropertyChangeSupport propertySupport= new PropertyChangeSupport(this);
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.addPropertyChangeListener(listener);
    }
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.removePropertyChangeListener(listener);
    }
    // Code block for changeListeners support end


    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.7617DEB4-3AE9-4C8B-1838-A697E3831917]
    // </editor-fold> 
    public Timeline () {
    }


    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.6F158EFA-F852-72DE-B899-4CA874901320]
    // </editor-fold> 
    public KeyFrame getKeyFrameAt(double t){
        Iterator<KeyFrame> iterator=myKeyFrames.iterator();
        KeyFrame res=null;

        while(iterator.hasNext()){
            res=iterator.next();
            if(res.getTime()==t)
                return res;
        }

        res=new KeyFrame();
        res.setTime(t);
        iterator=myKeyFrames.iterator();
        int position=0;
        while(iterator.hasNext()){
            if(iterator.next().getTime()<t)
                position++;
            else
                break;
        }
        myKeyFrames.add(position, res);
        return res;
    }

    public KeyFrame[] getKeyFramesArray(){
 
        return myKeyFrames.toArray(new KeyFrame[myKeyFrames.size()]);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker ">
    // #[regen=yes,id=DCE.CEC9C4B6-078F-C24C-8699-77D44C04BF65]
    // </editor-fold>
    private ArrayList<KeyFrame> myKeyFrames=new ArrayList<KeyFrame>();

}

